from blocks import *
def main():
    print "welcome to rapid slide builder"
    title=raw_input("Title: ")
    date=raw_input("Date/Place: ")
    presenter=raw_input("Name of Presenter: ")
    affiliation=raw_input("Affiliation of Presenter: ")
    
    # Initialization
    presentation=Presentation(title,date,presenter,affiliation)
    
    # Interactive Slide Creating
    path=[]
    current=presentation
    path.append(current)
    while(True):
        print "\n"
        print "==============================="
        print current.show()
        r=raw_input("a(append) o(output) u(up) x(exit)-->")
        if(r=="a"):
            if(current==presentation):
                tmp=Slide()
                current.addSlide(tmp)
                current=tmp
                path.append(current)
                continue                
            else:
                tag=raw_input("enter tag-->")
                if(tag=="ul"):
                    tmp=Block(tag)
                    current.addContent(tmp)
                    current=tmp
                    path.append(current)                    
                    continue
                elif(tag=="img"):
                    current.addImg(raw_input("filename: "))
                elif(tag=="h1"):
                    current.addTitle(raw_input("title: "))
                else:
                    current.addContent(Block(tag,Text(raw_input(tag+": "))))
                    continue
        elif(r=="u"):
            if(current==presentation):
                continue
            else:    
                path.pop()
                current=path[-1]
        elif(r=="o"):
            filename=raw_input("save as: ")
            if(filename):
                f=open(filename,'w')
                presentation.output(f)
            else:
                continue
        elif(r=="x"):
            confirm=raw_input("really want to exit?(yes/no): ")
            if(confirm=="yes"):
                break
            else:
                continue                    

                
if __name__=="__main__":
    main()